﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DTO_QLNS;

namespace ADO_QLNS
{
    public class GenreADO : QLNS_ADO
    {
        GenreDTO _DTO;

        public static int GetID(GenreDTO dto)
        {
            _Helper.Connect();
            int ID = -1;
            {
                string sql = "Select GenreID From Genre Where GenreName = {0}";
                sql = String.Format(sql, dto.GenreName);
                ID = (int)_Helper.exeScalar(sql);
            }
            _Helper.Disconnect();
            return ID;
        }

        protected override object GetDataFromDataRow(System.Data.DataTable dt, int i)
        {
            throw new NotImplementedException();
        }

        public override string InsertString(TransferObject dto)
        {
            _DTO = (GenreDTO)dto;
            string insertCmd = "INSERT INTO Genre( GenreName) VALUES('{0}')";
            return String.Format(insertCmd, _DTO.GenreName);
        }

        public override string UpdateString(TransferObject dto)
        {
            _DTO = (GenreDTO)dto;
            string updateCmd = "UPDATE Genre SET GenreName='{0}' WHERE GenreID={1})";
            return String.Format(updateCmd, _DTO.GenreName, _DTO.GenreID);
        }

        public override string DeleteString(TransferObject dto)
        {
            _DTO = (GenreDTO)dto;
            string deleteCmd = "DELETE FROM Genre WHERE GenreID={0}";
            return String.Format(deleteCmd, _DTO.GenreID);
        }
    }
}
